import 'api_response.dart';

/// 国标设备模型
class GBDevice {
  final int id; // WVP系统中的设备主键
  final String deviceId; // 国标设备ID
  final String name; // 设备名称
  final String manufacturer; // 设备厂商
  final String status; // 设备状态
  final String hostAddress;
  final int port;
  final String expires;
  final String registerTime;
  final String keepaliveTime;
  final String createTime;
  final String updateTime;
  final String charset;
  final String subscribeCycleForCatalog;
  final String subscribeCycleForMobilePosition;
  final String mobilePositionSubmissionInterval;
  final String subscribeCycleForAlarm;
  final String ssrcCheck;
  final String geoCoordSys;
  final String treeType;
  final String catalogGroup;
  final String administrativeDivision;
  final String catalogKeepSections;
  final String asMessageChannel;
  final String startOfflinePush;
  final String sippDirectly;
  final String transport;

  GBDevice({
    required this.id,
    required this.deviceId,
    required this.name,
    required this.manufacturer,
    required this.status,
    this.hostAddress = '',
    this.port = 0,
    this.expires = '',
    this.registerTime = '',
    this.keepaliveTime = '',
    this.createTime = '',
    this.updateTime = '',
    this.charset = '',
    this.subscribeCycleForCatalog = '',
    this.subscribeCycleForMobilePosition = '',
    this.mobilePositionSubmissionInterval = '',
    this.subscribeCycleForAlarm = '',
    this.ssrcCheck = '',
    this.geoCoordSys = '',
    this.treeType = '',
    this.catalogGroup = '',
    this.administrativeDivision = '',
    this.catalogKeepSections = '',
    this.asMessageChannel = '',
    this.startOfflinePush = '',
    this.sippDirectly = '',
    this.transport = '',
  });

  factory GBDevice.fromJson(Map<String, dynamic> json) {
    return GBDevice(
      id: json['id'] ?? 0,
      deviceId: json['deviceId'] ?? '',
      name: json['name'] ?? '',
      manufacturer: json['manufacturer'] ?? '',
      status: json['status'] ?? '',
      hostAddress: json['hostAddress'] ?? '',
      port: json['port'] ?? 0,
      expires: json['expires'] ?? '',
      registerTime: json['registerTime'] ?? '',
      keepaliveTime: json['keepaliveTime'] ?? '',
      createTime: json['createTime'] ?? '',
      updateTime: json['updateTime'] ?? '',
      charset: json['charset'] ?? '',
      subscribeCycleForCatalog: json['subscribeCycleForCatalog'] ?? '',
      subscribeCycleForMobilePosition: json['subscribeCycleForMobilePosition'] ?? '',
      mobilePositionSubmissionInterval: json['mobilePositionSubmissionInterval'] ?? '',
      subscribeCycleForAlarm: json['subscribeCycleForAlarm'] ?? '',
      ssrcCheck: json['ssrcCheck'] ?? '',
      geoCoordSys: json['geoCoordSys'] ?? '',
      treeType: json['treeType'] ?? '',
      catalogGroup: json['catalogGroup'] ?? '',
      administrativeDivision: json['administrativeDivision'] ?? '',
      catalogKeepSections: json['catalogKeepSections'] ?? '',
      asMessageChannel: json['asMessageChannel'] ?? '',
      startOfflinePush: json['startOfflinePush'] ?? '',
      sippDirectly: json['sippDirectly'] ?? '',
      transport: json['transport'] ?? '',
    );
  }
}

/// 国标设备列表响应
class GBDeviceListResponse {
  final int total;
  final List<GBDevice> rows;
  final int code;
  final String msg;

  GBDeviceListResponse({
    required this.total,
    required this.rows,
    required this.code,
    required this.msg,
  });

  factory GBDeviceListResponse.fromJson(Map<String, dynamic> json) {
    return GBDeviceListResponse(
      total: json['total'] ?? 0,
      rows: (json['rows'] as List?)?.map((e) => GBDevice.fromJson(e)).toList() ?? [],
      code: json['code'] ?? 500,
      msg: json['msg'] ?? 'Unknown error',
    );
  }

  bool get isSuccess => code == 200;
}

/// 国标设备详情响应
class GBDeviceDetailResponse extends ApiResponse<GBDevice> {
  GBDeviceDetailResponse({
    required int code,
    required String msg,
    GBDevice? data,
  }) : super(code: code, msg: msg, data: data);

  factory GBDeviceDetailResponse.fromJson(Map<String, dynamic> json) {
    return GBDeviceDetailResponse(
      code: json['code'] ?? 500,
      msg: json['msg'] ?? 'Unknown error',
      data: json['data'] != null ? GBDevice.fromJson(json['data']) : null,
    );
  }
} 